// pages/modifydetail/modifydetail.js
const App = getApp();

import Dialog from '@vant/weapp/dialog/dialog';
const {
  get,
  post
} = App.require('request/index')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    obj: {},
    navHeight: App.globalData.navHeight,
    prolist: wx.getStorageSync('prolist') == '' ? wx.getStorageSync('prolist') : JSON.parse(wx.getStorageSync('prolist')),
    numberSex: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */

  getdetail(e) {

    post('/app/exam/exam/detail', {
      id: e
    }).then(res => {
      this.setData({
        obj: Object.assign(res.data)
      })
    })
  },
  moday() { //this.data.prolist.userid
let {obj,prolist} = this.data
    post('/app/exam/paper/createPaper', {
      examId: obj.examId,
      memberId: prolist.userId 
    }).then(res => {
      if (res.success) {
        post('/app/exam/paper/paperDetail', {  
          id: res.data
        }).then(res => {
          let str = JSON.stringify(res.data)
          wx.navigateTo({
            url: `/pages/examadmin/pages/exam/exam?data=${str}`,
          })
        })    
      } else {
        Dialog.confirm({
          title: '提示',
          message: '您还有未答的试卷，请进入答题',
        })
        .then(() => {
          this.goks(obj.examId);
        })
        .catch(() => {
          // on cancel
        });
        
      }



    })
  },
  goks(e) {
    let {
      prolist
    } = this.data;
    post(`/app/exam/paper/checkProcess?memberId=${prolist.userId}`, {}).then(res => {
      post('/app/exam/paper/paperDetail', {
        id: res.data.id
      }).then(res => {
        let str = JSON.stringify(res.data) 
        wx.navigateTo({
          url: `/pages/examadmin/pages/exam/exam?data=${str}`,
        })
      })
    })
  },
  onLoad(options) {
    this.getdetail(options.id)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})